<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/share/taglib.jsp" %>
<%  String path = request.getContextPath(); %>
<html>
<head>
 	<title>注册-重庆模拟志愿填报系统</title>
	 <script type="text/javascript" src="<%=path%>/script/jquery-1.3.2.min.js"></script>
	<link href="<%=path%>/style/imitation.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript">
	</script>
</head>
<body>
<center>
 <jsp:include page="/head.jsp"/>
	<s:form action="userreg_register" namespace="/logon" id="usersaddui" method="post" onsubmit="">
	<table>
				<tr>
					<td class="span-3 rt"><dfn>*</dfn>用户名:</td>
					<td><s:textfield name="user.username" onblur="checkUserName()" onkeypress='$("#conmessage").html("")' id="userName"  cssClass="text5"/>
					<div style="display: block; margin-bottom: 0px; float: right;" id="conmessage" ></div>
					</td>
				</tr>
				<tr>
					<td class="span-3 rt"><dfn>*</dfn>密码:</td>
					
					<td><s:password name="newuserpass" id="newuserpass" cssClass="text5"/></td>
					
				</tr>
				<tr>
					<td class="span-3 rt"><dfn>*</dfn>确认密码:</td>
					<td><s:password name="confirmnewpass" id="confirmnewpass" cssClass="text5" /></td>
				</tr>
				<tr>
					<td class="span-3 rt"><dfn>*</dfn>电子邮件:</td>
					<td><s:textfield name="user.email" onblur="checkEmail()" onkeypress='$("#mailmessage").html("")'  id="userEmail" cssClass="text5" />
					<div style="display: block; margin-bottom: 0px;float: right;" id="mailmessage" ></div>
					</td>
				</tr>
				
				<tr>
					<td class="span-3 rt"><dfn>*</dfn>真实姓名:</td>
					<td><s:textfield name="user.realname" id="realname" cssClass="text5" /></td>
				</tr>
				
				</table>
				<h2></h2>
			<div class="clear">
			<input type="submit" id="savebutton" name="Submit" value="保存" tabindex="8" class="reg_btn blue_link" />
			<input type="button" name="back" value="返回" tabindex="8" class="reg_btn blue_link"
			onclick="javascript:history.go(-1);" />
			
			</div>
	</s:form>
 <jsp:include page="/foot.jsp"/>
</center>
	<script type="text/javascript" src="<%=path%>/script/jquery.validate-1.3.2.js"></script>
	 <script type="text/javascript" src="<%=path%>/script/jquery.validate.person.js"></script>
	 <script type="text/javascript" src="<%=path%>/script/jquery.validate.message_cn.js"></script>
<script type="text/javascript">
	$ (document).ready (function() {
		    $ ("#usersaddui").validate ({
		        rules: {
		            'newuserpass':{
		                required:true,
		                maxlength:20
		            },
		            'user.username': {
		                required:true,
		                maxlength:20
		            },
		            'user.email': {
		            	required:true,
		            	email:true,
		            	maxlength:20
		            },
		            'confirmnewpass': {
		                required:true,
						equalTo: "#newuserpass",
		                maxlength:20
		            }
		           
		        }
		    });

		});
	function checkUserName(){
		//alert($("#number").attr("value").length);
		if($("#userName").attr("value") == "" || $("#userName").attr("value").length >20 ){
			return false;
		}
		$("#conmessage").html("<img src='<%=path%>/images/ajax-loader.gif'/>");
		var params = $("#usersaddui").serialize();
		$.ajax({
			url:"<%=path%>/logon/userreg_checkUserByName.action",
			type:"POST",
			data:params,
			dataType:"json",
			success:function(data){
				//清空显示层中的数据
				//$("#conmessage").html("");
				if(data.message == "不存在"){
					 //$("#conmessage").html("<div><font color='red'>"+"不存在!"+"</font></div>")
					 $("#conmessage").html("<font color='green'>可用!</font>");
					 $('#savebutton').removeAttr("disabled");
				}
				else{//为显示层添加获取到的数据
					 $("#conmessage").html("已经存在，请换一个再试!");
					
					 $('#savebutton').attr('disabled',"true");

				}
			}
		});
	}

	function checkEmail(){
		//alert($("#number").attr("value").length);
		if($("#userEmail").attr("value") == "" || $("#userEmail").attr("value").length >20 || !isValidEmail($("#userEmail").attr("value"))){
			return false;
		}
		$("#mailmessage").html("<img src='<%=path%>/images/ajax-loader.gif'/>");
		var params = $("#usersaddui").serialize();
		$.ajax({
			url:"<%=path%>/logon/userreg_checkUserByEmail.action",
			type:"POST",
			data:params,
			dataType:"json",
			success:function(data){
				//清空显示层中的数据
				//$("#conmessage").html("");
				if(data.message == "不存在"){
					 //$("#conmessage").html("<div><font color='red'>"+"不存在!"+"</font></div>")
					 $("#mailmessage").html("<font color='green'>可用!</font>");
					 $('#savebutton').removeAttr("disabled");
				}
				else{//为显示层添加获取到的数据
					 $("#mailmessage").html("已经存在，请换一个再试!");
					
					 $('#savebutton').attr('disabled',"true");

				}
			}
		});
	}
	function isValidEmail(el)//用正则表达式判断
	{
	var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z-]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]|net|NET|asia|ASIA|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT|cn|CN|cc|CC)$"
	var re = new RegExp(regu);
	if(el.search(re) == -1)
	{
		return false; //非法
	}else
		return true;//正确
	}
	
 
</script>
</body>
</html>
